<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta
      name="viewport"
      content="initial-scale=1.0, user-scalable=no, width=device-width"
    />
    <style>
      html,
      body,
      #container {
        width: 100%;
        height: 100%;
      }
    </style>
    <title>折线的绘制和编辑</title>
    <link
      rel="stylesheet"
      href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css"
    />
    <link
      rel="stylesheet"
      href="https://unpkg.com/maptalks/dist/maptalks.css"
    />
    <script src="https://webapi.amap.com/maps?v=2.0&key=4a395735f5c4de042b2f7031475c183c&plugin=AMap.PolylineEditor"></script>
    <script src="https://a.amap.com/jsapi_demos/static/demo-center/js/demoutils.js"></script>

    <script
      type="text/javascript"
      src="https://unpkg.com/maptalks/dist/maptalks.min.js"
    ></script>
  </head>
  <body>
    <div id="container"></div>
    <script type="text/javascript">
      var map = new AMap.Map("container", {
        center: [116.395577, 39.892257],
        zoom: 14,
      });

      var path = [
        [116.362209, 39.887487],
        [116.422897, 39.878002],
        [116.372105, 39.90651],
        [116.428945, 39.89663],
      ];
      var path2 = [
        [
          [116.32873535156249, 40.01499435375046],
          [116.52099609375, 40.019201307686785],
          [116.49902343749999, 40.12849105685408],
        ],
        [
          [116.66931152343749, 40.0360265298117],
          [116.72973632812499, 40.14948820651523],
          [116.81213378906249, 40.01499435375046],
        ],
      ];
      var arrow = new AMap.Icon({
        image: "https://webapi.amap.com/images/car.png",
        imageSize: new AMap.Size(24, 24),
        iamgeOffset: new AMap.Pixel(-12, -12),
      });

      var polyline = new AMap.Polyline({
        path: path,
        isOutline: true,
        outlineColor: "#ffeeff",
        borderWeight: 3,
        strokeColor: "#3366FF",
        strokeOpacity: 1,
        strokeWeight: 6,
        // 折线样式还支持 'dashed'
        strokeStyle: "solid",
        // strokeStyle是dashed时有效
        strokeDasharray: [10, 5],
        lineJoin: "round",
        lineCap: "round",
        zIndex: 50,
        showDir: true,
        dirImg: arrow,
      });

      var polyline2 = new AMap.Polyline({
        path: path2,
        isOutline: true,
        outlineColor: "#ffeeff",
        borderWeight: 3,
        strokeColor: "#3366FF",
        strokeOpacity: 1,
        strokeWeight: 6,
        // 折线样式还支持 'dashed'
        strokeStyle: "dashed",
        // strokeStyle是dashed时有效
        strokeDasharray: [15, 5],
        lineJoin: "round",
        lineCap: "square",
        zIndex: 50,
      });
      map.add([polyline, polyline2]);
      map.setFitView();
      var layer = new maptalks.VectorLayer("vector").addTo(map);

      var line = new maptalks.LineString(
        [
          map.getCenter().sub(0.1, 0),
          map.getCenter().add(0.1, 0),
          map.getCenter().add(0.1, -0.1),
        ],
        {
          arrowStyle: "classic", // we only have one arrow style now
          arrowPlacement: "vertex-firstlast", //vertex-first, vertex-last, vertex-firstlast, point
          symbol: {
            lineColor: "#1bbc9b",
            lineWidth: 8,
          },
        }
      ).addTo(map);
    </script>
  </body>
</html>
